import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * author: MaHX
 * date: 2019/8/24/19:30
 * description:
 **/
public class Test {
    public static void main(String args[]) {
        int i = 128;
        int j = 128;
        Integer i001 = 128;  //与int比较时会自动拆箱为int  <=> Integer i0001 = Integer.valueOf(128);
        Integer i002 = 128;  //类型范围内,若相等则直接在常量池中拿，不用新建
        Integer i003 = new Integer(128);
        System.out.println(i==j);   //true
        System.out.println(i==i001);//true
        System.out.println(i001==i002);//false  在常量池中只保存-128~127之间的整数
        System.out.println(i001==i003); // new 是在堆中新建对象，并把引用地址给i003  //false
        System.out.println("----------------------------");


//        StringBuffer sb = new StringBuffer("Hello ");
//
//        System.out.println("Before change, sb = " + sb);
//
//        changeData(sb);
//
//        System.out.println("After changeData(n), sb = " + sb);
//    }
//
//    private static void changeData(StringBuffer strBuf) {
//        StringBuffer sb2 = new StringBuffer("Hi ");
//        strBuf = sb2;
//        sb2.append("World!");
//    }

//
//        Integer a = 1;
//        Integer b = 2;
//        System.out.println("a:" + a + " b:" + b);
//        swap(a, b);
//        System.out.println("a:" + a + " b:" + b);


        String a = "Programming";
        String b = new String("Programming");
        String c = "Program" + "ming";
        System.out.println(a == b);   //false
        System.out.println(a == c);   //true
        System.out.println(a.equals(b)); //true
        System.out.println(a.equals(c)); //true
        System.out.println(a.intern() == b.intern()); //true

        HashMap<String,String> hashMap = new HashMap<String, String>();
        hashMap.put("1","杨过");
//        hashMap.put("2","小龙女");
//        System.out.println(hashMap.get("1"));
//        for (Map.Entry<String ,String > entry: hashMap.entrySet()
//             ) {
//            System.out.println(entry.getKey()+" : "+entry.getValue());
//        }
//        Iterator<String>
//    }
//
    }
        private static void swap (Integer a, Integer b){
            Integer temp = a;
            a = b;
            b = temp;
        }
}
